package com.yayohos.locationmanager.providers.dialogprovider;


import com.yayohos.locationmanager.listener.DialogListener;
import com.yayohos.locationmanager.providers.permissionprovider.DefaultPermissionProvider;

import ohos.agp.window.dialog.BaseDialog;
import ohos.app.Context;

import java.lang.ref.WeakReference;

/**
 * DialogProvider父类
 *
 * @date 2021/5/26
 */
public abstract class DialogProvider {
    private WeakReference<DialogListener> weakDialogListener;

    /**
     * Create a dialog object on given context
     *
     * @param context in which the dialog should run
     * @return dialog object to display
     */
    public abstract BaseDialog getDialog(Context context);

    /**
     * 获取DialogListener
     *
     * @return DialogListener
     */
    public DialogListener getDialogListener() {
        return weakDialogListener.get();
    }

    /**
     * Sets a {@linkplain DialogListener} to provide pre-defined actions to the component which uses this dialog
     * <p>
     * This method will be called by {@linkplain DefaultPermissionProvider} internally, if it is in use.
     *
     * @param dialogListener will be used to notify on specific actions
     */
    public void setDialogListener(DialogListener dialogListener) {
        this.weakDialogListener = new WeakReference<>(dialogListener);
    }
}
